﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommonTagTime;
using CommonTagTime.Business;
using CommonTagTime.ModelObject;

public partial class _Default : SitePage
{
    //------------------------------------------------
    //VARIABLES
    //------------------------------------------------

    //------------------------------------------------
    //METHODS
    //------------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //this.Page.Header.Title = "";
            
            _LoadContentPage();
            //_LoadNews();
            _LoadBanner();
        }
    }


    protected void rptNewProduct_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
        Product data = new Product();
        if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
        {
            if (data == null)
                return;

            data = (Product)item.DataItem;

            ucProductItem uc = (ucProductItem)item.FindControl("ProductItem");
            uc.ProductItem = data;
            uc.Type = 1;
        }
    }

    protected void dalHotProduct_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        DataListItem item = e.Item;
        Product data = new Product();
        if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
        {
            if (data == null)
                return;

            data = (Product)item.DataItem;

            ucProductItem uc = (ucProductItem)item.FindControl("ProductItem");
            uc.ProductItem = data;
        }
    }

    private void _LoadContentPage()
    {
        busContentPage objbus = new busContentPage();
        ContentPage objData = objbus.GetByURL("/");
        this.SetMetaData(string.Format(Resources.Resource.TITLE, Server.HtmlEncode(objData.Name)), objData.MetaDescription, objData.MetaKeywords);
        //ltrContentPage.Text = objData.Content;
    }

    private void _LoadBanner()
    {
        Logo objLogo = new Logo();
        objLogo.CurrentPage = 1;
        objLogo.OrderBy = busLogo.SortOrder;
        objLogo.OrderDirection = "ASC";
        objLogo.PageSize = Int16.MaxValue;
        objLogo.Condition = " l.[Position]=4 ";

        busLogo _busLogo = new busLogo();
        int total = 0;
        LogoCollection lstResult = _busLogo.List(objLogo);
        total = objLogo.TotalRecords;
        if (lstResult != null && lstResult.Count > 0)
        {
            rptBannerBot.DataSource = lstResult;
        }

        rptBannerBot.DataBind();
    }

    private void _LoadNews()
    {
        //TipNewsCollection lstResult = new TipNewsCollection();
        //busTipNews objBus = new busTipNews();

        //TipNews objTipNews = new TipNews();
        //objTipNews.CurrentPage = 1;
        //objTipNews.OrderBy = busTipNews.CREATEDDATE;
        //objTipNews.OrderDirection = "DESC";
        //objTipNews.PageSize = 4;
        //objTipNews.Condition = "t.IsActive=1 and t.[Type]='" + (int)enmTipNewsType.NewEvent + "'";
        //lstResult = objBus.List(objTipNews);
        //int count = 0;
        //if (lstResult != null && lstResult.Count > 0)
        //{
        //    NewsItem.objNews = lstResult[0];

        //    if (lstResult.Count > 1)
        //    {
        //        ltrRelatedNews1.Text = string.Format(@"<span class=""item-time"">{2}</span> <i><a href=""/news/{0}/{3}"">{1}</a></i>", clsText.ToSEO(lstResult[1].Title), lstResult[1].Title, lstResult[1].CreatedDate.ToString("dd.MM.yyyy"), lstResult[1].TipNewsID.ToString());
        //    }
        //    if (lstResult.Count > 2)
        //    {
        //        ltrRelatedNews2.Text = string.Format(@"<span class=""item-time"">{2}</span> <i><a href=""/news/{0}/{3}"">{1}</a></i>", clsText.ToSEO(lstResult[2].Title), lstResult[2].Title, lstResult[2].CreatedDate.ToString("dd.MM.yyyy"), lstResult[2].TipNewsID.ToString());
        //    }
        //}

        
    }
}